Skip to content

feat: implement enricher#1715

Open
k11kirky wants to merge 1 commit intomainfrom
04-17-feat_implement_enricher
Open

feat: implement enricher#1715
k11kirky wants to merge 1 commit intomainfrom
04-17-feat_implement_enricher

Conversation

@k11kirky
Copy link
Copy Markdown
Contributor

@k11kirky k11kirky commented Apr 17, 2026

TLDR

Adds a file enrichment feature that annotates PostHog-related code with live metadata (event volume, flag rollout/staleness, experiment links) as the agent reads files.

Problem

When the agent reads source files containing PostHog SDK calls, it has no awareness of the current state of those flags or events in production. This means the agent lacks important product context — such as whether a flag is rolled out, how much volume an event has, or whether an event is verified — that would help it make better recommendations.

Changes

  • Introduces a new @posthog/enricher package dependency in the agent, with a FileEnrichmentDeps/Enrichment abstraction in packages/agent/src/enrichment/file-enricher.ts that wraps PostHogEnricher and exposes an enrichFileForAgent function
  • For the Claude adapter, a PostToolUse hook (createReadEnrichmentHook) intercepts Read tool responses, strips line numbers, runs enrichment, and returns additionalContext to the model alongside writing enriched content to an EnrichedReadCache keyed by tool_use_id; the cache is consumed in toolUpdateFromToolResult so the UI displays the annotated version
  • For the Codex adapter, enrichment is applied directly inside readTextFile on the CodexClient, replacing the file content before it reaches codex-acp
  • Adds a toInlineComments() method on EnrichedResult that appends PostHog annotations as inline comments on the same source line (rather than inserting new lines above), and a corresponding formatInlineComments function in the comment formatter
  • API errors (401, 500, network failures, malformed JSON) in enrichFromApi are now tolerated via Promise.allSettled rather than rejecting, returning partial/empty enrichment instead
  • Fixes a HogQL query bug where typed placeholders ({name:Type}) and INTERVAL with a placeholder were rejected; daysBack is now inlined directly into the query string
  • Enrichment is enabled by default when posthog config is present and can be disabled via enricher: { enabled: false } in AgentConfig
  • Grammar file resolution in ParserManager now checks multiple candidate paths to support packaged Electron app layouts; the forge.config.ts asar unpack glob and a new copyEnricherGrammars Vite plugin ensure grammars are available at both dev and packaged runtime paths
  • CI build and test workflows include a build step for @posthog/enricher
  • Adds unit tests for enrichFileForAgent, createReadEnrichmentHook, and createCodexClient.readTextFile

Copy link
Copy Markdown
Contributor Author

This stack of pull requests is managed by Graphite. Learn more about stacking.

@k11kirky k11kirky force-pushed the 04-17-feat_implement_enricher branch 2 times, most recently from 17cf4dc to 319d5b1 Compare April 18, 2026 15:01
@k11kirky k11kirky marked this pull request as ready for review April 20, 2026 13:06
@k11kirky k11kirky force-pushed the 04-17-feat_implement_enricher branch from 319d5b1 to 065a0f3 Compare April 20, 2026 15:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants